package lock.lock;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 描述：Lock不会像synchronized一样，异常的时候自动释放锁，因此最佳实践是在finally中释放锁，以便保证发生异常的时候锁一定被释放
 */

public class MustUnlock {
    private static Lock lock = new ReentrantLock();
    public static void main(String[] args) {
        lock.lock();
        try {
            System.out.println("lock");
            throw new RuntimeException();
        } finally {
            lock.unlock();
        }
    }
}
